import { ApiProperty } from "@nestjs/swagger";
import { $Enums, SysUser } from "@prisma/client";

import { jwtConstants } from "@/core/auth/constants";

export class LoginVo implements Omit<SysUser, "deletedAt" | "password" | "isDeleted"> {
    @ApiProperty()
    id: number;
    @ApiProperty()
    avatar: string;
    @ApiProperty()
    username: string;
    @ApiProperty()
    nickname: string;
    @ApiProperty()
    isDisabled: boolean;
    @ApiProperty()
    lastLoginIp: string;
    @ApiProperty()
    lastLoginAt: Date;
    @ApiProperty()
    createdAt: Date;
    @ApiProperty()
    updatedAt: Date;

    @ApiProperty()
    isSuper: boolean;
    @ApiProperty()
    sort: number;
    @ApiProperty()
    isMultipoint: boolean;
    @ApiProperty()
    email: string;

    @ApiProperty()
    phone: string;
    @ApiProperty()
    isFixed: boolean;
    @ApiProperty()
    realname: string;
    @ApiProperty()
    gender: $Enums.Gender;

    @ApiProperty()
    token: string;
    @ApiProperty()
    token_expiration: number;

    constructor(user: SysUser, token: string) {
        this.id = user.id;
        this.avatar = user.avatar;
        this.username = user.username;
        this.nickname = user.nickname;
        this.isDisabled = user.isDisabled;
        this.lastLoginIp = user.lastLoginIp;
        this.lastLoginAt = user.lastLoginAt;
        this.createdAt = user.createdAt;
        this.updatedAt = user.updatedAt;
        this.isSuper = user.isSuper;
        this.sort = user.sort;
        this.isMultipoint = user.isMultipoint;
        this.email = user.email;
        this.phone = user.phone;
        this.isFixed = user.isFixed;
        this.realname = user.realname;
        this.gender = user.gender;

        this.token = token;
        this.token_expiration = Date.now() + jwtConstants.expiresIn * 1000;
    }
}
